package com.liming.admin.controller;

import com.liming.admin.service.CouponService;
import com.liming.common.pojo.dto.coupon.AddCouponDTO;
import com.liming.common.pojo.dto.coupon.CouponPageQuery;
import com.liming.common.pojo.dto.coupon.UpdateCouponDTO;
import com.liming.common.pojo.vo.PageVO;
import com.liming.common.pojo.vo.coupon.web.CouponVO;
import com.liming.common.result.LMResult;
import com.liming.coupon.client.CouponAdminClient;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * @author liming
 * @date 2025/1/18
 */
@Slf4j
@RestController
@AllArgsConstructor
@Tag(name = "优惠券接口-Web")
@RequestMapping("/admin/coupon")
public class CouponController {

    private final CouponAdminClient couponAdminClient;
    private final CouponService couponService;

    @Operation(
            summary = "列表",
            responses = {
                    @ApiResponse(responseCode = "1", description = "成功", content = {
                            @Content(mediaType = "application/json", schema = @Schema(implementation = CouponVO.class))
                    })
            }
    )
    @GetMapping
    public LMResult<PageVO<CouponVO>> page(CouponPageQuery query) {
        return LMResult.success(couponService.page(query));
    }


    @Operation(
            summary = "详情",
            responses = {
                    @ApiResponse(responseCode = "1", description = "成功", content = {
                            @Content(mediaType = "application/json", schema = @Schema(implementation = CouponVO.class))
                    })
            }
    )
    @GetMapping("{id}")
    public LMResult<CouponVO> get(@PathVariable Long id) {
        return LMResult.success(couponService.get(id));
    }

    @Operation(summary = "新增")
    @PostMapping
    public LMResult<Boolean> add(@RequestBody AddCouponDTO addCouponDTO) {
        return LMResult.success(couponAdminClient.add(addCouponDTO));
    }

    @Operation(summary = "启用/禁用优惠券")
    @PutMapping("upd_available/{id}")
    public LMResult<Boolean> updAvailable(@PathVariable Long id) {
        return LMResult.success(couponAdminClient.updAvailable(id));
    }

    @Operation(summary = "更新")
    @PutMapping
    public LMResult<Boolean> update(@RequestBody UpdateCouponDTO updateCouponDTO) {
        return LMResult.success(couponAdminClient.update(updateCouponDTO));
    }

    @Operation(summary = "删除")
    @DeleteMapping("{id}")
    public LMResult<Boolean> delete(@PathVariable Long id) {
        return LMResult.success(couponAdminClient.deleteCoupon(id));
    }
}
